package com.cn.code.contentService.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.cn.code.contentService.TabContentService;
import com.cn.code.dao.baseDao.BaseDao;
import com.cn.code.domain.TabContentTitleVo;
import com.cn.code.domain.TabContentVo;
@Service(value="tabContentService")
public class TabContentServiceImpl extends BaseDao implements TabContentService {
	
	public TabContentVo find(String id) {
		return	hibernateTemplate.get(TabContentVo.class, id);
	}

	
	public void saveOrUpdate(TabContentVo tabContentVo) {
		hibernateTemplate.saveOrUpdate(tabContentVo);
	}

	
	public TabContentVo save(TabContentVo tabContentVo) {
		hibernateTemplate.save(tabContentVo);
		return tabContentVo;
	}

	
	public TabContentVo update(TabContentVo tabContentVo) {
		hibernateTemplate.update(tabContentVo);
		return tabContentVo;
	}


	public List<?> queryTitles(Integer pageNo, int pageSize, String type) {
		TabContentTitleVo vo = new TabContentTitleVo();
		vo.setType(type);
		List list =hibernateTemplate.findByExample(vo, (pageNo-1)*pageSize, pageNo*pageSize);
		return list;
	}


	public Integer queryTitlesCount(String type) {
		StringBuffer hqlBuffer = new StringBuffer("select count(sys) from TabContentTitleVo sys where 1=1 ");
		if(type!=null){
			 hqlBuffer.append(" and sys.type= '"+type+"' ");
		}
		Integer count = Integer.valueOf(hibernateTemplate.find(hqlBuffer.toString()).listIterator().next()+"");
		return count;
	}


	public TabContentTitleVo findContentTitle(String id) {
		
		return hibernateTemplate.get(TabContentTitleVo.class, id);
	}


	public TabContentVo findContentVo(String id) {
		TabContentVo vo = new TabContentVo();
		vo.setTitleId(id);
		List list=hibernateTemplate.findByExample(vo);
		if(list!=null && list.size()>0){
			return (TabContentVo) list.get(0);
		}
		return null;
	}


	public TabContentVo findContentVoByType(String type) {
		TabContentVo vo = new TabContentVo();
		vo.setType(type);
		List list=hibernateTemplate.findByExample(vo);
		if(list!=null && list.size()>0){
			return (TabContentVo) list.get(0);
		}
		return null;
	}

}
